home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / mst.h < prev    next >
C/C++ Source or Header  |  1991-09-12  |  7KB  |  276 lines

  1. /***********************************************************************
  2.  *
  3.  *    Generic inclusions.
  4.  *
  5.  ***********************************************************************/
  6.  
  7. /***********************************************************************
  8.  *
  9.  * Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  10.  * Written by Steve Byrne.
  11.  *
  12.  * This file is part of GNU Smalltalk.
  13.  *
  14.  * GNU Smalltalk is free software; you can redistribute it and/or modify it
  15.  * under the terms of the GNU General Public License as published by the Free
  16.  * Software Foundation; either version 1, or (at your option) any later 
  17.  * version.
  18.  * 
  19.  * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  20.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  21.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  22.  * more details.
  23.  * 
  24.  * You should have received a copy of the GNU General Public License along with
  25.  * GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  26.  * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  27.  *
  28.  ***********************************************************************/
  29.  
  30.  
  31. /*
  32.  *    Change Log
  33.  * ============================================================================
  34.  * Author      Date       Change 
  35.  * sbyrne    23 Sep 89      Modifications to support operation on a DECstation 3100.
  36.  *
  37.  * sbyrne    13 Sep 89      Sigh!!! modified pushOOP and setStackTop to move the
  38.  *              objects that they refer to to toSpace...good bye
  39.  *              performance!
  40.  *
  41.  * sbyrne    29 Dec 88      Created.
  42.  *
  43.  */
  44.  
  45. #ifndef __MST__
  46. #define __MST__
  47.  
  48. #include "mstconfig.h"
  49.  
  50. /* The system version flags */
  51. #define sysVersMajor        1 
  52. #define sysVersMinor        1 
  53. #define sysVersEdit        1
  54.  
  55. /* Enable this definition to count different types of byte code executions */
  56. /* #define countingByteCodes */
  57.  
  58.  
  59. #define baseInt            (((unsigned long)3)<<30)
  60. #define highBitMask        (((unsigned long)1)<<31) /* just hi bit */
  61.  
  62. #ifndef USE_BCOPY
  63. #include <memory.h>
  64. #define bcopy(s2, s1, n)  memcpy(s1, s2, n)
  65. #define bzero(s,l) memset(s,'\0',l)
  66. #endif /* USE_BCOPY */
  67.  
  68. /*#if !defined(__STDC__) && (defined(AIX) | defined(mips) | defined(ibm032) || (defined(sun) && !defined(SUNOS40))) */
  69. #if !defined(__STDC__) && defined(OLDCC)
  70. /* for older compilers that don't understand void * and enums are ints */
  71. #define nil            0
  72. typedef char *voidPtr;
  73. #define ENUM_INT(x)           ((int)(x))
  74. typedef int Boolean;
  75. #define false            0
  76. #define true            1
  77.  
  78. #else 
  79. typedef void *voidPtr;
  80. #define nil            (voidPtr)0
  81. #define ENUM_INT(x)        (x)
  82.  
  83. typedef enum booleanType {
  84.   false,
  85.   true
  86. } Boolean;
  87.  
  88. #endif
  89.  
  90.  
  91. /* Would someone (this means you!) please test this out on this machine and 
  92.  * see if this can be merged with the code above a little more cleanly?
  93.  */
  94. #if defined(hp9000s300)
  95. #undef ENUM_INT
  96. #define ENUM_INT(x)            ((int)(x))
  97. #endif
  98.  
  99. /* The set of checks here should either be expanded, or in the m-*.h files
  100.    there should be a definition that talks about the required alignment
  101.    for doubles, whether they must be on a 4 or 8 byte boundary. */
  102. #if defined(sparc) || defined(hppa)
  103. #define DOUBLE_ALIGNMENT    sizeof(double)
  104. #else
  105. #define DOUBLE_ALIGNMENT    sizeof(long)
  106. #endif
  107.  
  108.  
  109.  
  110. typedef struct StreamStruct    *Stream;
  111.  
  112. typedef struct OOPStruct    *OOP;
  113. typedef struct ObjectStruct    *Object;
  114.  
  115. struct OOPStruct {
  116.   Object    object;
  117.   union {
  118.     struct {
  119. #ifdef BIG_ENDIAN
  120.       unsigned    i_isFree : 1;    /* pack these tighter as needed to make long */
  121.       unsigned  i_evenMark : 1;    /* for OOP table garbage collector */
  122.       unsigned  i_oddMark : 1;    /* for OOP table garbage collector */
  123.       char    i_emptyBytes;   /* 3 number of unused bytes at end; subtract
  124.                    from computed byte length to get the real
  125.                    length of data */
  126.       char    i_inSpace;    /* 0 => space 0, 1 => space 1 */
  127. #else
  128.       char    i_emptyBytes;   /* number of unused bytes at end; subtract
  129.                    from computed byte length to get the real
  130.                    length of data */
  131.       char    i_inSpace;    /* 0 => space 0, 1 => space 1 */
  132.       unsigned    : 13;
  133.       unsigned  i_oddMark : 1;    /* for OOP table garbage collector */
  134.       unsigned  i_evenMark : 1;    /* for OOP table garbage collector */
  135.       unsigned    i_isFree : 1;    /* pack these tighter as needed to make long */
  136. #endif
  137.     } w2_i;
  138. /*    long    w2_prevFree; */
  139.   } w2;
  140. };
  141.  
  142. #define isFree        w2.w2_i.i_isFree
  143. #define emptyBytes    w2.w2_i.i_emptyBytes
  144. #define inSpace        w2.w2_i.i_inSpace
  145. #define evenMark    w2.w2_i.i_evenMark
  146. #define oddMark        w2.w2_i.i_oddMark
  147. /* #define prevFree    w2.w2_prevFree */
  148.  
  149. extern struct OOPStruct  oopTable[];
  150.  
  151. /* The header of all objects in the system */
  152. #define OBJ_HEADER \
  153.   long        objSize; /* for now, this is object size in 32bit words*/ \
  154.   OOP        objClass
  155.  
  156. /* just for symbolic use in sizeof's */
  157. typedef struct ObjectHeaderStruct {
  158.   OBJ_HEADER;
  159. } ObjectHeader;
  160.  
  161. #define OBJ_HEADER_SIZE_WORDS    (sizeof(ObjectHeader) / sizeof(long))
  162.  
  163. struct ObjectStruct {
  164.   OBJ_HEADER;
  165.   OOP        data[1];    /* variable length, may not be objects, but
  166.                    will always be at least this big. */
  167. };
  168.  
  169. extern    OOP        *sp;
  170. extern    char        *nilName;
  171. extern    OOP        nilOOP, trueOOP, falseOOP, thisClass;
  172. extern    Boolean        regressionTesting;
  173.  
  174.  
  175. typedef unsigned char Byte;
  176.  
  177. #define TreeNode        void * /* dummy decl */
  178.  
  179.  
  180. /*
  181.  * Macros for common things...can be functions for debugging or can be 
  182.  * macros for speed.
  183.  */
  184.  
  185. #ifndef NO_INLINE_MACROS
  186.  
  187. #define uncheckedPushOOP(oop) \
  188.   *++sp = (oop)
  189.  
  190. /* YUCK!!!! I HATE TO DO THIS!!!! DAMN GARBAGE COLLECTOR!!!! */
  191. #define pushOOP(oop) \
  192. { \
  193.   OOP __tempOOP = (oop); \
  194.   maybeMoveOOP(__tempOOP); \
  195.   uncheckedPushOOP(__tempOOP); \
  196.  
  197. #define popOOP() \
  198.   (*sp--)
  199.  
  200. #define popNOOPs(n) \
  201.   sp -= (n)
  202.  
  203. #define unPop(n) \
  204.   sp += (n)
  205.  
  206. #define stackTop() \
  207.   (*sp)
  208.  
  209. /* UGH!!! DAMN GC!!!  I wish we could run without it! */
  210. #define setStackTop(oop) \
  211. { \
  212.   OOP __tempOOP = (OOP)(oop); \
  213.   maybeMoveOOP(__tempOOP); \
  214.   *sp = __tempOOP; \
  215. }
  216.  
  217. #define stackAt(i) \
  218.   (sp[-(i)])
  219.  
  220. #define pushInt(i) \
  221.   uncheckedPushOOP(fromInt(i))
  222.  
  223. #define popInt() \
  224.   toInt(popOOP())
  225.  
  226. #define pushBoolean(exp) \
  227.   uncheckedPushOOP((exp) ? trueOOP : falseOOP)
  228.  
  229. #define oopToObj(oop) \
  230.   (oop->object)
  231.  
  232. #define oopClass(oop) \
  233.   (oopToObj(oop)->objClass)
  234.  
  235. #define isClass(oop, class) \
  236.   (isOOP(oop) && oopClass(oop) == class)
  237.  
  238. /* integer conversions */
  239.  
  240. #define toInt(oop) \
  241.   ( (long) ((unsigned long)(oop) - baseInt) )
  242.  
  243. #define fromInt(i) \
  244.   (OOP)(((unsigned long)(i) + baseInt) | highBitMask)
  245.  
  246. /*
  247.  * for these, we could probably get away with just hacking the number and
  248.  * setting the high bit.
  249.  */
  250. #define incrInt(i) \
  251.   fromInt(toInt(i) + 1)
  252.  
  253. #define decrInt(i) \
  254.   fromInt(toInt(i) - 1)
  255.  
  256.  
  257.  
  258. #define isInt(oop) \
  259.   ((long)(oop) < 0)
  260.  
  261. #define isOOP(oop) \
  262.   ((long)(oop) >= 0)
  263.  
  264. /* general functions */
  265.  
  266. #define isNil(oop) \
  267.   ((OOP)(oop) == nilOOP)
  268.  
  269. /* return the number of availble longwords in object, excluding the header */
  270. #define numOOPs(obj) \
  271.   ( 1 + (obj)->objSize - (sizeof(struct ObjectStruct) / sizeof(Object)) )
  272. #endif /* NO_INLINE_MACROS */
  273.  
  274. #endif /* __MST__ */
  275.